package com.ityang.config;

import org.apache.shardingsphere.api.sharding.standard.PreciseShardingAlgorithm;
import org.apache.shardingsphere.api.sharding.standard.PreciseShardingValue;

import java.text.SimpleDateFormat;
import java.util.Collection;

public class SharedingTablePreciseAlgorithm implements PreciseShardingAlgorithm<String> {
    public SharedingTablePreciseAlgorithm() {
    }

    private String DateToTable(String tablePre, PreciseShardingValue preciseShardingValue){
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMM");
        return tablePre+ sdf.format(preciseShardingValue.getValue());
    }

    @Override
    public String doSharding(Collection<String> collection, PreciseShardingValue<String> preciseShardingValue) {
        return DateToTable("t_order_",preciseShardingValue);
    }
}